<template>
  <div class="dialog-container">
    <el-dialog
      v-model="dialogVisible"
      :before-close="handleClose"
      :title="title"
      width="40%"
    >
      <el-form label-position="left" label-width="100px">
        <el-form-item label="方案类型">
          <el-select v-model="data.Solution" placeholder="请选择">
            <el-option
              v-for="item in solutionList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="版本号">
          <el-input v-model="data.VersionNo" disabled style="width: 350px" />
        </el-form-item>
        <el-form-item label="显示模式">
          <el-select v-model="data.VersionName" placeholder="请选择">
            <el-option
              v-for="item in versionNameList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="版本类型">
          <el-select v-model="data.VerType" placeholder="请选择">
            <el-option
              v-for="item in verTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="版本描述">
          <el-input v-model="data.Remark" style="width: 350px" />
        </el-form-item>
        <el-form-item label="状态">
          <el-switch
            v-model="data.Status"
            active-value="1"
            inactive-value="0"
          />
        </el-form-item>
        <el-form-item label="文件上传">
          <!-- <el-input v-model="data.CSName" style="width: 350px" /> -->
          <FileUpload :version-data="data" @success="uploadSuccessed" />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="handleClose">取消</el-button>
          <el-button type="primary" @click="confirm">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue'
  import { editcsver } from '@/api/mupro'
  import FileUpload from './fileUpload.vue'
  const props = defineProps({
    visible: {
      type: Boolean,
      default: false,
    },
    data: {
      type: Object,
      default() {
        return {}
      },
    },
    title: {
      type: String,
      default: '编辑',
    },
  })
  const solutionList = ref([
    {
      label: '睿赛德',
      value: '',
    },
    {
      label: '合一智联',
      value: 's1',
    },
  ])
  const versionNameList = ref([
    {
      label: '横屏',
      value: '0',
    },
    {
      label: '竖屏',
      value: '2',
    },
  ])
  const verTypeList = ref([
    {
      label: '程序升级',
      value: '0',
    },
    {
      label: '固件升级',
      value: '1',
    },
  ])
  const dialogVisible = ref(false)
  const data: any = ref(JSON.parse(JSON.stringify(props.data)))
  watch(
    () => props.visible,
    () => {
      dialogVisible.value = props.visible
      if (props.visible) {
        data.value = JSON.parse(JSON.stringify(props.data))
        console.log(data.value)
      }
    }
  )
  const emit = defineEmits(['close', 'confirm'])
  const handleClose = () => {
    dialogVisible.value = false
    emit('close', dialogVisible.value)
  }
  const confirm = async () => {
    await editcsver(data.value)
    emit('confirm', data.value)
    // dialogVisible.value = false
  }
  const uploadSuccessed = (path: string) => {
    data.value.VersionUrl = path
  }
</script>

<style lang="scss" scoped>
  .tag {
    font-size: 14px;
  }
</style>
